path = 'test03.txt'
with open(file=path, mode='r', encoding='utf-8') as f:
    # 读取文件全部内容
    print(f.read())
    print('++++++++++++++')
with open(file=path, mode='r', encoding='utf-8') as f:
    # 读取5个字符
    print(f.read(5))
    print('++++++++++++++')
with open(file=path, mode='r', encoding='utf-8') as f:
    # 读取第一行的n个字符
    print(f.readline(1))
    print(f.readline(2))
    print('++++++++++++++')
with open(file=path, mode='r', encoding='utf-8') as f:
    # 读取文件全部内容 按照行读取
    print(f.readlines())
    print('++++++++++++++')
with open(file=path, mode='r', encoding='utf-8') as f:
    # 读取文件第n行
    print(f.readlines(1))
    print(f.readlines(2))
    print('++++++++++++++')
with open(file=path, mode='r', encoding='utf-8') as f:
    # 迭代读取
    for line in f:
        print(line,end='')
